package org.example.sword2offer.primary;

/**
 * @author: lynn
 * @Descript:
 * @date: 2021/7/8 19:03
 * @version: 1.0
 */
public class Q69_1_TwoAscendingArray {

    public void merge(int A[], int m, int B[], int n) {
        int i = m - 1;
        int j = n - 1;
        int index = A.length-1;//AB合并后最后一个元素所在位置
        while(i >= 0 && j>= 0)//AB合并，谁大就先放谁
            A[index --] = A[i] > B[j] ? A[i --] : B[j --];
        while(j >= 0)//如果B没有遍历完，那么之间丢在A数组里面
            A[index--] = B[j --];

        while (i>=0){
            A[index--] = A[i --];
        }
    }

    public static void main(String[] args) {
        int[] A={1,2,3,0,0,0}; //fixme 后面露出的
        int[] B={2,5,6};
        Q69_1_TwoAscendingArray mergeTwoList=new Q69_1_TwoAscendingArray();
        mergeTwoList.merge(A,3,B,3);
        System.out.println("XXXXXX");
    }
}
